package flowchart.app;

/*
 * Programming graphicxal user interfaces
 */

import flowchart.nodes.*;
import java.awt.BorderLayout;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;


/**
 * The diagram application main window. Includes the entry point
 * of the application.
 */
public class DiagramApp extends JFrame
{
     JMenuBar mb;
   public DiagramApp(String title) {
      super(title);

      Picture defaultpic = createInitialPicture();
      //creating menu 
      mb = new JMenuBar();
      setJMenuBar(mb);

      //creating buttonbar
     JToolBar toolBar = new JToolBar();
     add(toolBar,BorderLayout.PAGE_START);
     JTextField t = new JTextField();
     add(t);
       //create diagram view, pass menu and toolbar objects
      DiagramView dv = new DiagramView(t,defaultpic,mb,toolBar);
      getContentPane().add(dv);
      this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
      this.addWindowListener(new Exiter(dv));
     

   }


   // Load an initial Picture
    private Picture createInitialPicture() {

        Picture drawing=null;
        String imgname="/flowchart/resources/welcome2.wtf";
        try{
            ObjectInputStream in = new ObjectInputStream(getClass().getResourceAsStream(imgname));
            drawing = (Picture) in.readObject();

        }catch(Exception e){
            System.out.println("Could not load opening image");
        }
        finally{
            if (drawing == null)
                drawing = new Picture();
            return drawing;
        } 
   }

   public static void main(String[] args) {
      JFrame f = new DiagramApp("WTF-Editor");
      f.setBounds(100, 100, 520, 550);
      f.setVisible(true);

   }
   
   // an inner class for exiting the application
   
}
